package com.saleoffline.server;

import java.util.ArrayList;
import java.util.List;

public class Search extends BaseObject {
	private static int LIMIT_SIZE = 20;
	private String keyword;
	private int offset;
	private int limit;
	private List<OrderByItem> orderByItems;
	
	public List<OrderByItem> addOrderByItem(OrderByItem orderByItem) {
		if (orderByItems == null) {
			orderByItems = new ArrayList<OrderByItem>();
		}
		orderByItems.add(0, orderByItem);
		return orderByItems;
	}
	
	public List<OrderByItem> getOrderByItems() {
		return orderByItems;
	}

	public void setOrderByItems(List<OrderByItem> orderByItems) {
		this.orderByItems = orderByItems;
	}
	
	public static enum SortType {
		ASC, DESC
	}

	public static class OrderByItem {
		private String columnName;
		private SortType sortType;
		
		public OrderByItem(String columnName, SortType sortType) {
			this.columnName = columnName;
			this.sortType = sortType;
		}
		
		public String getColumnName() {
			return columnName;
		}
		public void setColumnName(String columnName) {
			this.columnName = columnName;
		}
		public SortType getSortType() {
			return sortType;
		}
		public void setSortType(SortType sortType) {
			this.sortType = sortType;
		}
	}

	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	public int getLimit() {
		if (limit < 1) {
			return LIMIT_SIZE;
		}
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}
}
